<!DOCTYPE html>
<html>
<head>
    {include file="public/header" /}
    <style>
        .prizeconfirm .layui-layer-btn {
            height:50%;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .prizeconfirm .layui-layer-btn .layui-layer-btn0{
            border: 1px solid #dedede;
            background-color: #fff;
            color: #333;
            border-radius: 2px;
        }
        .prizeconfirm .layui-layer-content{
            display: none;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <!--<input type="hidden" name="id" value="{$info.id}">-->
    <!--<div class="layui-form-item">-->
        <!--<label class="layui-form-label required">活动名称</label>-->
        <!--<div class="layui-input-block">-->
            <!--<input type="text" name="title" lay-verify="required" lay-reqtext="活动名称不能为空" placeholder="请输入活动名称" value="{$info.title}" class="layui-input" autocomplete="off">-->
        <!--</div>-->
    <!--</div>-->
    <!--<div class="layui-form-item">-->
        <!--<label class="layui-form-label">开始时间</label>-->
        <!--<div class="layui-input-inline">-->
            <!--<input type="text" name="start_time" id="start_time"  placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input" value="{$info.start_time}">-->
        <!--</div>-->
        <!--<div class="layui-inline">-->
            <!--<label class="layui-form-label">下架时间</label>-->
            <!--<div class="layui-input-inline">-->
                <!--<input type="text" name="end_time" id="end_time"  placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input" value="{$info.end_time}">-->
            <!--</div>-->
        <!--</div>-->
    <!--</div>-->

    <!--<div class="layui-form-item layui-form-text">-->
        <!--<label class="layui-form-label">活动说明</label>-->
        <!--<div class="layui-input-block">-->
            <!--<textarea name="detail" class="layui-textarea" lay-verify="required" placeholder="请输入活动说明">{$info.detail}</textarea>-->
        <!--</div>-->
    <!--</div>-->
    <!--<div class="layui-form-item">-->
        <!--<label class="layui-form-label">状态</label>-->
        <!--<div class="layui-input-block">-->
            <!--<input type="checkbox" name="status" value="{$info.status}" lay-skin="switch" lay-filter="switchTest" lay-text="开启|关闭" {if condition='$info.status==1'}checked=""{/if}>-->
        <!--</div>-->
    <!--</div>-->
    <div class="layui-form-item">
        <label class="layui-form-label">奖项设置</label>
        <div class="layui-input-block">
            <button class="layui-btn" onclick="createPrize(3)">创建奖项</button>
        </div>
    </div>
    <div class="layui-form-item" id="prize_table">

    </div>
    <!--<div class="layui-form-item">-->
        <!--<label class="layui-form-label">题目设置</label>-->
        <!--<div class="layui-input-block">-->
            <!--<button class="layui-btn" onclick="setQuestion()">选择题目</button>-->
        <!--</div>-->
    <!--</div>-->
    <!--<div class="layui-form-item" >-->
        <!--<div class="layui-input-block" id="question_table">-->
            <!--<table class="layui-table">-->
               <!--<thead>-->
                    <!--<th>序号</th>-->
                    <!--<th>名称</th>-->
                    <!--<th>操作</th>-->
               <!--</thead>-->
                <!--<tbody>-->
                <!--{volist name="question" id="v"}-->
                    <!--<tr>-->
                        <!--<input type="hidden" class="question_id" name="question_id[]" value="{$v.id}">-->
                        <!--<td>{$v.id}</td>-->
                        <!--<td>{$v.title}</td>-->
                        <!--<td><a class="layui-btn  layui-btn-xs layui-btn-danger data-count-delete" onclick="deleteQuestion(this)">删除</a></td>-->
                    <!--</tr>-->
                <!--{/volist}-->
                <!--</tbody>-->
            <!--</table>-->
        <!--</div>-->
    <!--</div>-->
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script src="/static/admin/prize.js"></script>
<script>
    $(function(){
        getsPrizeList(3);
    })
    layui.use(['form','laydate'], function () {
        var form = layui.form,
            layer = layui.layer,
            laydate=layui.laydate,
            $ = layui.$;
        // 上架开始日期
        var insShelf = laydate.render({
            elem: '#start_time'
            , min: 0
            , calendar: true
            , type: 'datetime'
            , done: function (value, date) {
                //更新结束日期的最小日期
                insUnder.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });

                //自动弹出结束日期的选择器
                //insUnder.config.elem[0].focus();
            }
        });
        //上架结束日期
        var insUnder = laydate.render({
            elem: '#end_time'
            , min: 0
            , calendar: true
            , type: 'datetime'
            , done: function (value, date) {
                //更新开始日期的最大日期
                insShelf.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });
        //监听指定开关
        form.on('switch(switchTest)', function (data) {
            if(this.checked){
                this.value=1;
            }else{
                this.value=2;
            }
        });
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            //data.field.status = data.field.status ? 1 : 2;
            $.ajax({
                url: "/admin/Active/daliyanswer_write?action=ajax",
                type: 'post',
                async: true,
                data: data.field,
                dataType: 'json',
                success: function (res) {
                    if(res.status){
                        layer.msg("操作成功!", {icon:1,time: 1000}, function () {
                            //重新加载父页面
                            location.reload();
                        });
                        return;
                    }else{
                        layer.msg(res.msg);
                    }
                }
            });
            return false;
        });
    });

    function setQuestion()
    {
        // 已选择的问题拼接
        let id_con=$(".question_id").map(function () {
            return $(this).val();
        }).get().join(",");
        layer.open({
            type: 2 ,
            title: "设置问题",
            area: ['1000px', '630px'],
            shade: 0.5,
            maxmin: true,
            content: '/admin/Active/set_question?id_con='+id_con
        })
    }

    function setQuestionModel(data)
    {
        let str="<table class=\"layui-table\">\n" +
            "                <thead>\n" +
            "                <th>序号</th>\n" +
            "                <th>名称</th>\n" +
            "                <th>操作</th>\n" +
            "                </thead>\n" +
            "                <tbody>\n";

        data.map(function(e){
            str+="                <tr>\n" +
                "                    <input type=\"hidden\" class=\"question_id\" name=\"question_id[]\" value=\""+e.id+"\">\n" +
                "                    <td>"+e.id+"</td>\n" +
                "                    <td>"+e.title+"</td>\n" +
                "                    <td> <a class=\"layui-btn  layui-btn-xs layui-btn-danger data-count-delete\" onclick=\"deleteQuestion(this)\">删除</a></td>\n" +
                "                </tr>\n" ;
        });
        str+=
            "                </tbody>\n" +
            "\n" +
            "            </table>";
        $("#question_table").html(str);
    }
    function deleteQuestion(obj)
    {
        $(obj).parents("tr").remove();
    }
</script>
</body>
</html>